package com.stylefeng.guns.rest.modular.App.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import com.stylefeng.guns.core.model.Pager;
import com.stylefeng.guns.rest.Tools.Result;
import com.stylefeng.guns.rest.common.annotion.SSO;
import com.stylefeng.guns.rest.modular.App.model.NoticeInf;
import com.stylefeng.guns.rest.modular.App.service.INoticeInfService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 通知信息
 *
 * @author sasazaixian
 * @Date 2018-11-15 16:38
 */
@Controller
@RequestMapping(value = {"/gunsApi/auth/noticeInf"})
@Api(value = "通知信息操作相关api", tags = {"通知信息操作接口"})
public class NoticeInfController extends BaseController {
    @Autowired
    private INoticeInfService noticeInfService;
	
    /**
     * 分页获取通知信息列表
     * @param noticeInf
     * @return	
     */
    @ApiOperation(value = "分页获取通知信息列表", notes = "分页获取通知信息列表", httpMethod = "POST")
    @PostMapping(value = "/pageList", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    @SSO
    public Result pageList( @RequestBody @ApiParam(name = "noticeInf", value = "通知信息对象")NoticeInf noticeInf) {

        if(noticeInf==null || noticeInf.getPageNum()==null || noticeInf.getPageSize()==null){
            return Result.error("必要参数不全！");
        }
        try {
            Pager pager=new Pager();
            pager.setPageNumber(noticeInf.getPageNum());//页码从1 开始
            pager.setPageSize(noticeInf.getPageSize());
            pager.setObj(noticeInf);			
            return Result.success( noticeInfService.pageListNoticeInf(pager,getToken()));
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }
    /**
     * 获取通知信息列表
     * @param noticeInf    
     * @return	
     */
    @ApiOperation(value = "获取通知信息列表", notes = "获取通知信息列表", httpMethod = "POST")
    @PostMapping(value = "/list", produces = MediaType.APPLICATION_JSON_UTF8_VALUE,consumes= MediaType.APPLICATION_JSON_UTF8_VALUE)	
    @ResponseBody
    @SSO
    public Result list(
        @RequestBody @ApiParam(name = "noticeInf", value = "通知信息对象")NoticeInf noticeInf) {
        try {            
            return Result.success( noticeInfService.selectListNoticeInf(noticeInf,getToken()));
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }
    /**
     * 通过主键获取通知信息对象
     * @param id
     * @return
     */
    @ApiOperation(value = "通过主键获取通知信息对象", notes = "通过主键获取通知信息对象", httpMethod = "GET")
    @GetMapping(value = "/getById", produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    @ResponseBody
    @SSO
    public Result getById(
            @ApiParam(name = "id", value = "主键ID", required = true) @RequestParam(value = "id", required = true) String  id
    ) {
        try {
            return Result.success( noticeInfService.findNoticeInfById(id,getToken()));
        }catch(Exception e){
            return Result.error(e.getMessage(),500100);
        }
    }
	private String getToken(){		
		return getHttpServletRequest().getHeader("Authorization").substring(7);
    }
}
